package com.irdstudio.tdp.executor.rest.enums;

import org.springframework.util.StringUtils;


/**
 * Executor模式枚举类
 * @author ligm
 * @date 2019-10-22
 */
public enum ExecutorModeEnum {
	
	HSF(1, "hsf", "Executor启动模式-支持HSF"), DUBBO(2, "dubbo", "Agent启动模式-支持DUBBO"), LOCAL(3, "local", "Agent启动模式-支持LOCAL");

	private int index;
	private String code;
	private String text;
	
	private ExecutorModeEnum(int index, String code, String text) {
		this.index = index;
		this.code = code;
		this.text = text;
	}
	
	/**
	 * 返回枚举项的索引
	 * @return
	 */
	public int getIndex() {
		return this.index;
	}

	/**
	 * 返回枚举项的描述
	 * @return
	 */
	public String getText() {
		return text;
	}

	/**
	 * 返回枚举项的值
	 * @return
	 */
	public String getCode() {
		return code;
	}
	
	/**
	 * 根据代码返回对应枚举值对象
	 * @param code
	 * @return
	 */
	public static ExecutorModeEnum getEnumByCode(String code) {
		if (StringUtils.isEmpty(code)) {
			return null;
		}
		for (ExecutorModeEnum enums : ExecutorModeEnum.values()) {
			if (enums.getCode().equals(code)) {
				return enums;
			}
		}
		return null;
	}
}
